package com.tdam2013.grupo09.funcionalidad;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.widget.Toast;

public class NetworkConnectivity extends BroadcastReceiver {

	private static boolean conectividad = true;

	@Override
	public void onReceive(Context context, Intent intent) {
		ConnectivityManager connMgr = (ConnectivityManager) context
				.getSystemService(Context.CONNECTIVITY_SERVICE);
		NetworkInfo networkInfo = connMgr.getActiveNetworkInfo();

		// NetworkInfo networkInfo =
		// connMgr.getNetworkInfo(ConnectivityManager.TYPE_WIFI);

		if (networkInfo != null && networkInfo.isConnectedOrConnecting()) {
			conectividad = true;
			Toast.makeText(context, "La red esta habilitada",
					Toast.LENGTH_SHORT).show();

		} else {
			conectividad = false;
			Toast.makeText(context, "Desconectado", Toast.LENGTH_SHORT).show();

		}
	}

	public static boolean getConectividad() {
		return conectividad;
	}

}


